package com.IC.base.controller;

import com.IC.base.service.AdministrativeDivisionService;
import IC.common.core.domain.R;
import com.IC.domain.Division;
import com.github.pagehelper.PageInfo;
import com.IC.domain.po.AdministrativeDivisionPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/division")
public class AdministrativieDivisionController {

    @Autowired
    private AdministrativeDivisionService administrativeDivisionService;
    @Autowired
    private RedisTemplate<String, Object> baseRedisTemplate;

    @GetMapping("/list")
    public R list(@RequestParam(name = "name", required = false)String name, @RequestParam(name = "divisionCode",required = false)String divisionCode) {

        List<AdministrativeDivisionPO> findlist = administrativeDivisionService.findlist(name, divisionCode);
        return R.ok(findlist);
    }

    @PostMapping("/add")
    public R add(@RequestBody Division division) {
        administrativeDivisionService.add(division);
        return R.ok();
    }

    @GetMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        administrativeDivisionService.removeById(id);
        return R.ok();
    }

    @PostMapping("/update")
    public R update(@RequestBody Division division) {
        administrativeDivisionService.updByid(division);
        return R.ok();
    }





//    @GetMapping("/list")
//    public R get() {
//        List<AdministrativeDivisionPO> list = (List<AdministrativeDivisionPO>) baseRedisTemplate.opsForValue().get("AdministrativeDivisionList");
//        if (list==null){
//            list = administrativeDivisionService.list();
//            baseRedisTemplate.opsForValue().set("AdministrativeDivisionList",list);
//        }
//        return R.ok(list);
//    }

}
